package com.itcodai.dao.user;

import com.itcodai.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author c-fanqj
 * @date 2023/3/22
 * @apiNote
 */
//@Mapper
public interface UserMapper /*extends MyMapper<User>*/ {

    //void deleteUser(Long id);

    @Select("select * from user where id = #{id}")
    @Results({
            @Result(property = "username", column = "user_name"),
            @Result(property = "password", column = "password")
    })
    //@Results("BaseResultMap")   // xml和注解相结合使用
    User getUser(Long id);

    @Select("select * from user where id = #{id} and user_name = #{name}")
    // @Param 指定的参数应该要和 sql 中 #{} 取的参数名相同，不同则取不到
    User getUserByIdAndName(@Param("id") Long id, @Param("name") String username);

    @Select("select * from user")
    List<User> getAll();

    // 使用xml方式
    User getUserByName(String username);

    @Insert("insert into user (user_name, pass_word) values (#{username}, #{password}) ")
    Integer insertUser(User user);


}
